<?php

//require_once('forum/SSI.php');

function siteinfo($show='root') {
    switch ($show) {
        case 'root' :
            $output = ROOT_DIR;
            break;
        case 'includes' :
            $output = INCLUDES_DIR;
            break;
        case 'script' :
            $output = SCRIPTS_DIR;
            break;
        case 'media':
            $output = MEDIA_DIR;
            break;
        case 'style' :
            $output = STYLES_DIR;
            break;
        case 'url' :
            $output = SITE_URL;
    }

    return $output;
}

function isUserLogged() {
    global $context;
    if(!$context['user']['is_logged']) {
        return false;
    }
    else {
        $_SESSION['username'] = $context['user']['username'];
        $proba = md5($context['user']['username'] + 'motherfuckingzajebanistring');
        $_SESSION['proba'] = $proba;
        return true;
    }
}

function checkIfUserIsAdmin($user) {
    if (isUserLogged()) {
        if ($user['nivopristupa']==100) return true;
    }
    return false;
}

//http://www.reddit.com/r/PHP/comments/75dzi/how_do_i_find_a_url_in_a_string_of_input_using/
function convertToTinyUrl($content) {
    preg_match_all('((?:http)://\S+[[:alnum:]]/?)si', $content, $out);
    $i = 0;
    while ($i < count($out)) {
        $convert = $out['0'][$i];
        $tinystring = "<a href=\"$convert\" target=\"_blank\" rel=\"nofollow\">{link}</a>";
        $content = str_replace($convert, $tinystring, $content);
        $i++;
    }
    return $content;
}

//Ne koristi se jos uvek
function redirect($url,$permanent = false)
{
  if($permanent)
  {
    header('HTTP/1.1 301 Moved Permanently');
  }
  header('Location: '.$url);
  exit();
}

function getYouTubeId($url) {
  $re1='.*?';	# Non-greedy match on filler
  $re2='(v)';	# Any Single Character 1
  $re3='(=)';	# Any Single Character 2
  $re4='((?:[a-z][a-z0-9_]*))';	# Variable Name 1
  $re5='(&)';	# Any Single Character 3

  if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5."/is", $txt, $matches))
  {
      //$c1=$matches[1][0];
      //$c2=$matches[2][0];
      $var1=$matches[3][0];
      //$c3=$matches[4][0];
      return $var1;
  }
}

// Shows a login box.
function login_box($redirect_to = '')
{
	global $scripturl, $txt, $user_info, $context, $modSettings;

	if ($redirect_to != '')
		$_SESSION['login_url'] = $redirect_to;

	if (!$user_info['is_guest'])
		return $user_info['is_guest'];

	return '
		<form action="'. $scripturl.  '?action=login2" method="post" accept-charset="'. $context['character_set']. '">
			<fieldset>
                            <label for="user">Korisni&#269ko ime:</label><br />
                            <input class="inp_text" name="user" id="user" type="text" value="" /><br />
                            <a href="?page=registracija" title="Kreirajte nalog na sajtu Tattoo Portal.org">Niste registrovani?</a>
                        </fieldset>
                        <fieldset>
                            <label for="passwrd">Lozinka:</label><br />
                            <input class="inp_text" name="passwrd" id="signin_password" type="password" /><br />
                            <a href="forum/?action=reminder" title="Kliknite ovde ukoliko ste zaboravili Vašu lozinku">Zaboravljena lozinka?</a>
                        </fieldset>
                        <fieldset>
                            <td><input type="hidden" name="cookielength" value="-1" /></td>
                            <input class="inp_butt" name="signin_submit" id="signin_submit" type="submit" value="Prijavi se" />
                            </fieldset>
		</form>';

}

//Mysql realy escape strings
function mres($input) {
    db_connect();

    if (get_magic_quotes_gpc ()) {
        $input = stripslashes($input);
    }

    return mysql_real_escape_string($input);
}

?>